/* 
 * File:   mmu.h
 * Author: lsboss
 *
 * Created on 13. Dezember 2009, 07:32
 */

#ifndef _MMU_H
#define	_MMU_H

/**
 * Pagetable Typen:
 *
 * <pre>
 *            //  Type  Pagetable size Page size(s)  # PageTableEntries
 *  -------------------------------------------------------------------
 *    COARSE  //  L2     1 KB          4 / 64 KB          256
 *    FINE    //  L2     4 KB          1 / 4 / 64 KB     1024
 *    MASTER  //  L1    16 KB          1024 KB           4096
 *    FAULT   //  kein Eintrag
 * </pre>
 */
typedef enum {
    FAULT = 0,
    COARSE,
    MASTER,
    FINE    
} page_table_type_t;

/**
 * Pagetable Domäne beschreibt Zugriffsrechte für Tabelleneintrag nach
 * CPU-Modus.
 */
typedef enum {
    NOACCESS    = 0,
    CLIENT      = 1,
    RSERVED     = 2,
    MANAGER     = 3
} page_table_domain_t;

/**
 * Feinere Steuerung der Zugriffsrechte nach Tabelleneintrag.
 */
typedef enum {
    NANA    = 0,  ///< No Access in both privileged and user mode
    RWNA    = 1,  ///< Read/Write access in privileged mode, no access in user mode
    RWRO    = 2,  ///< Read/Write access in privileged mode, Read Only access in user mode
    RWRW    = 3,  ///< Read/Write access in both privileged and user mode
} region_access_permission_t;

/**
 * CPU Cache einstellungen für eine Page
 */
typedef enum {
    NOTCACHED_NOTBUFFERED = 0,
    NOTCACHED_BUFFERED    = 1,
    CACHE_WRITETHROUGH    = 2,
    CACHE_WRITEBACK       = 3
} region_cache_config_t;


int init_mmu();

void mmu_map_memory(unsigned long physicalAddress,
        unsigned long number_of_1mb_blocks,
        unsigned long virtualAddress,
        region_access_permission_t access_permission,
        page_table_domain_t domain);

void *mmu_alloc_pages(int n);
void mmu_free_pages(void *page, int n);

#endif	/* _MMU_H */

